package com.pj.wisdomlogistics.utils;

import android.content.Intent;
import android.graphics.Bitmap;
import android.os.Environment;

import com.pj.wisdomlogistics.ui.activity.BaseActivity;
import com.pj.wisdomlogistics.ui.activity.SignActivity;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * Created by WuFan on 2017/10/20.
 */

public class ToSign {
    private static  int requestCode  = 1;

    public static void sign(final BaseActivity mContext){
        Intent mIntent = new Intent(mContext , SignActivity.class);
        mIntent.putExtra("class" , mContext.getClass().getSimpleName());
        mContext.startActivityForResult(mIntent , requestCode);
    }

    public static String createFile(Bitmap mBitmap) {
        ByteArrayOutputStream baos = null;
        String _path = null;
        try {
            String sign_dir = Environment.getExternalStorageDirectory()
                    + File.separator;
            _path = sign_dir + System.currentTimeMillis() + ".png";
            baos = new ByteArrayOutputStream();
            mBitmap.compress(Bitmap.CompressFormat.PNG, 100, baos);
            byte[] photoBytes = baos.toByteArray();
            if (photoBytes != null) {
                new FileOutputStream(new File(_path)).write(photoBytes);
            }
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            try {
                if (baos != null)
                    baos.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return _path;
    }

}
